package com.service.actions;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.HibernateException;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
//import com.service.hibernate.dao.GenericDAO;
import com.service.hibernate.dao.ServiceUsesDAO;
import com.service.hibernate.dao.StockViewDAO;

//import com.service.hibernate.pojos.ServiceUses;
import com.service.hibernate.pojos.Stocks;

@SuppressWarnings("serial")
public class StoreViewAction extends ActionSupport implements
		ModelDriven<Stocks> {

	private int sId;
	Stocks stock = new Stocks();
	//ServiceUses serviceUse = new ServiceUses();
	
	String item_id = "";
	
	List<Stocks> stocksList = new ArrayList<Stocks>();
	//List<ServiceUses> svs = new ArrayList<ServiceUses>();
	
	StockViewDAO stocksDAO = new StockViewDAO();
	ServiceUsesDAO serviceUsesDAO = new ServiceUsesDAO();
	

	@Override
	public Stocks getModel() {
		return stock;
	}
	
	public int getsId() {
		return sId;
	}

	public void setsId(int sId) {
		this.sId = sId;
	}



	public String execute() {
		try {

			stocksList = stocksDAO.getAllData("Stocks",Integer.toString(stock.getItem_id()));

			return SUCCESS;
		} catch (HibernateException e) {
			return ERROR;
		}

	}

	public String addItem() {
		try {
			stocksDAO.addData(stock);

			return SUCCESS;
		} catch (Exception e) {
			return ERROR;
		}

	}

/*	public String addToCart() {
		try {
			System.out.println("Item id is " + serviceUse.getQuantity());
			String result = serviceUsesDAO.addCart(serviceUse);

			return result;
		} catch (Exception e) {
			return ERROR;
		}

	}*/

	public String saveOrUpdate() {
		try {
			stocksDAO.saveOrUpdateStock(stock);
			return SUCCESS;
		}

		catch (Exception e) {
			return ERROR;
		}
	}

	public String viewForIssueItem() {
		try {

			stocksList = stocksDAO.getAllData("stocks",Integer.toString(stock.getItem_id()));

			return SUCCESS;
		} catch (HibernateException e) {
			return ERROR;
		}

	}

	/*public String viewServiceUse() {
		try {

			System.out.println("service id is "
					+ sId);
			svs = serviceUsesDAO
					.getService(1);

			return SUCCESS;
		} catch (HibernateException e) {
			return ERROR;
		}

	}*/

	public String listStocks() {
		try {
			stocksList = stocksDAO.getAllData("stocks",item_id);
			return SUCCESS;
		} catch (HibernateException e) {
			return ERROR;
		}

	}

	public Stocks getStock() {
		return stock;
	}

	public void setStock(Stocks stock) {
		this.stock = stock;
	}

	public List<Stocks> getStockes() {
		return stocksList;
	}

	public void setStockes(List<Stocks> stockes) {
		this.stocksList = stockes;
	}

/*	public ServiceUses getServiceUse() {
		return serviceUse;
	}

	public void setServiceUse(ServiceUses serviceUse) {
		this.serviceUse = serviceUse;
	}*/

}
